#pragma once

#include "OscOutboundPacketStream.h"
#include "UdpSocket.h"
#include "IpEndpointName.h"
#include "TcpServer.h"
#include "tstring.h"
#include "SMT.h"
using namespace std;


#define MAX_BUF_SIZE 2048
#define MAX_FLOAT_SIZE 48


class CMTDriveServer
{
public:
	CMTDriveServer(void);
	virtual ~CMTDriveServer(void);

	bool InitServer(const char *pcHostName, long lPort,  bool bOSC, bool bUDP, long lWidth, long lHeight);
	bool ShutDown();

	void SendXML();
	void SendOSC();
	void SetPort(long lPort);
	void SetHost(const char *pcHostName);
	void SetPanalSize(long lWidth, long lHeight);
	
	// Test
	bool UpdateCursor(int iCurID, float fX, float fY);
	bool UpdateCursor();

private:
	
	bool UpdateCursorOSC(int iCurID, float fX, float fY);
	bool UpdateCursorXML(int iCurID, float fX, float fY);
	static DWORD WINAPI UpdataSensor(void *pData);

	struct CMTCursor
	{
		int ID;
		float x;
		float y;
		float dx;
		float dy;
		float m;
	}m_cmtCursor;

	struct CMTCursorChar
	{
		char ccID[MAX_FLOAT_SIZE];
		char cX[MAX_FLOAT_SIZE];
		char cY[MAX_FLOAT_SIZE];
		char cDX[MAX_FLOAT_SIZE];
		char cDY[MAX_FLOAT_SIZE];
		char cM[MAX_FLOAT_SIZE];
	}m_cmtCursorChar;

	struct CMTSession
	{
		char cstrHost[128];
		unsigned long lPort;
		unsigned long lFseq;
		char cPort[MAX_FLOAT_SIZE];
		char cFseq[MAX_FLOAT_SIZE];
	}m_cmtSession;

	TcpServer *m_TcpServer;
	UdpTransmitSocket *m_UdpServer;
	long m_lWidth;
	long m_lHeight;
	bool m_bOSC;
	bool m_bUDP;
	bool m_bRunThread;
	HANDLE  m_thread;
	char m_buffer[MAX_BUF_SIZE];
	osc::OutboundPacketStream *m_pOSCPacket;
	string m_strXML;

	SMT_SENSOR m_cmtSensor;
	std::vector<SMT_CURSOR> m_vCursors;
	
};
